from zhipuai import ZhipuAI

from env.envParams import ZHIPU_API_KEY

client = None


def initialize_client():
    global client
    client = ZhipuAI(api_key=ZHIPU_API_KEY)


def getAIResult(input):
    if not client:
        initialize_client()
    response = client.chat.completions.create(
        model="glm-4-flash",  # 填写需要调用的模型编码
        messages=[
            {"role": "user", "content": input},
        ],
        temperature=0.2,
    )
    return response.choices[0].message.content
